<template>
  <div class="page-container padding-20 query-list-container">
    <div>
      <div class="search-container">
        <el-form :inline="true" ref="form" :model="searchData" size="small">
          <el-form-item label="关键字搜索">
            <el-input v-model="searchData.channel" placeholder="经销商名称"></el-input>
          </el-form-item>
          <el-form-item label="接出方式">
            <el-select v-model="searchData.way">
              <!-- <el-option
                v-for="status in statusList"
                :key="status.value"
                :label="status.label"
                :value="status.value"
              ></el-option> -->
            </el-select>
          </el-form-item>
          <el-button type="primary" @click="onSearch" size="small">查询</el-button>
          <el-button @click="onReset" size="small">重置</el-button>
        </el-form>
      </div>
      <el-table class="mt-20 el-table-modify" :data="tableData" border>
        <el-table-column type="index" label="序号" align="center" width="50"></el-table-column>
        <el-table-column prop="method" align="center" label="接触方式"></el-table-column>
        <el-table-column prop="channel" align="center" label="接出渠道"></el-table-column>
        <el-table-column prop="address" align="center" label="地址"></el-table-column>
        <el-table-column prop="date" align="center" label="操作时间">
          <template slot-scope="scope">
            {{scope.row.date | dateFrm}}
          </template>
        </el-table-column>
        <!-- <el-table-column label="操作" align="center" fixed="right" width="72">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="linkToDealear(scope.row)">查看经销商</el-button>
            <el-button size="mini" type="text" @click="payMoney(scope.row)">打款</el-button>
          </template>
        </el-table-column> -->
      </el-table>
      <el-pagination
        ref="pagination"
        class="mt-20"
        background
        :page-size="pageOption.pageSize"
        :total="pageOption.total"
        @size-change="onSizeChange"
        @current-change="onPageChange"
        layout="slot,->,prev,pager,next,sizes,jumper"
      >
        <span
          class="pagination-title"
        >共 {{pageOption.total}} 条记录 第 {{pageOption.page}} / {{pageOption.pageTotal}} 页</span>
      </el-pagination>
    </div>
  </div>
</template>

<script>
import {interafceQuery} from '@/api/interface';

export default {
  name: "InterfaceMgt",
  components: {},
  data() {
    return {
      searchData: {
        channel: "",
        way: "",
      },
      tableData: [],
      pageOption: {
        page: 1,
        pageSize: 20,
        total: 0,
        pageTotal: 1
      }
    };
  },
  methods: {
    onSearch() {
      this.pageOption.page = 1;
      this.requestData();
    },
    onReset() {
      this.pageOption.page = 1;
      this.searchData.channel = '';
      this.searchData.way = '';
      this.requestData();
    },
    async requestData() {
      const {page, pageSize : size} = this.pageOption   
      const postData = {}, searchData = this.searchData;
      Object.keys(searchData).forEach(item => {
        if (searchData[item]) {
          postData[item] = searchData[item];
        }
      })
      
      const {data, total} = await interafceQuery({page: page - 1, size, ...postData});
      this.tableData = data;
      this.pageOption.total = total;
      this.pageOption.pageTotal = total ? Math.ceil(total / size) : 1

      if (this.$refs.pagination) {
        let childrenRefs = this.$refs.pagination.$children
        this.$nextTick(() => {
          childrenRefs.forEach(child => child.$forceUpdate())
        });
      }
    },
    onSizeChange(size) {
      this.pageOption.pageSize = size;
      this.requestData();
    },
    onPageChange(page) {
      this.pageOption.page = page;
      this.requestData();
    },
  },
  created() {
    this.requestData();
  }
};
</script>

<style lang="scss">
</style>